package store.lunangangster.engine.impl.entity.mgr;

import java.util.List;
import store.lunangangster.engine.ProcessEngineConfiguration;
import store.lunangangster.engine.impl.entity.MesListenerEntity;
import store.lunangangster.engine.impl.entity.MesListenerEntityImpl;

public class MesListenerEntityManagerImpl extends AbstractEntityManagerImpl<MesListenerEntity> implements MesListenerEntityManager {

  public MesListenerEntityManagerImpl(
      ProcessEngineConfiguration processEngineConfiguration) {
    super(processEngineConfiguration);
  }

  @Override
  public Class<? extends MesListenerEntity> getManagedEntityClass() {
    return MesListenerEntityImpl.class;
  }

  @Override
  public MesListenerEntity create() {
    return new MesListenerEntityImpl();
  }

  @Override
  public List<MesListenerEntity> selectMesListenerByMessageId(String messageId) {
    return getDbSqlSession().getSqlSession()
        .selectList("selectMesListenerByMessageId", messageId);
  }

  @Override
  public void deleteMesListenerByExecutionId(String executionId) {
    // using cache but not delete directly
    MesListenerEntity mesListener = (MesListenerEntity) getDbSqlSession().selectOne(
        "selectMesListenerByExecutionId", executionId);
    getDbSqlSession().delete(mesListener);
  }
}
